﻿Imports System.Xml
Imports System.Text
Imports System.IO

Public Class FiltroDateTimeXml
    Inherits XmlTextWriter

    Private _datasParaAlterar() As String
    Private _alterar As Boolean

    Public Sub New(ByVal arquivo As String, ByVal datasParaAlterar() As String)
        MyBase.New(arquivo, Encoding.UTF8)
        _datasParaAlterar = datasParaAlterar
        Me.WriteStartDocument(True)
    End Sub

    Public Overloads Overrides Sub WriteStartElement(ByVal prefix As String, ByVal localName As String, ByVal ns As String)
        MyBase.WriteStartElement(prefix, localName, ns)
        For Each s As String In _datasParaAlterar
            If s.ToLower() = localName.ToLower() Then
                _alterar = True
            End If
        Next
    End Sub

    Public Overloads Overrides Sub WriteString(ByVal text As String)
        If _alterar Then
            Dim dt As DateTime = DateTime.Parse(text)
            text = dt.ToString("yyyy-MM-dd")
            _alterar = False
        End If
        MyBase.WriteString(text)
    End Sub
End Class
